<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>煤炭管理系统</title>
    <link rel="stylesheet" href="/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/lib/layui/css/layui-theme-custom.css">
    <link rel="stylesheet" href="/static/css/member.css">
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <#include "/base/main-header.ftl">
    <#include "/base/main-left.ftl">
    <div class="layui-body">
        <!-- 内容主体区域  -->
        <div class="site-title">
            <fieldset>
                <legend>
                    <a class="site-title-text">添加用户</a>
                </legend>
            </fieldset>
        </div>
        <div class="table-box">
            <div class="site-text site-block">
                <form action="" class="layui-form">
                    <div class="layui-form-item">
                        <label for="memberName" class="layui-form-label label-width">用户名：</label>
                        <div class="layui-input-block input-width">
                            <input type="text" name="userName" required  lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="name" class="layui-form-label label-width">姓名：</label>
                        <div class="layui-input-block input-width">
                            <input type="text" name="nickName" required  lay-verify="required" placeholder="请输入姓名" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="email" class="layui-form-label label-width">邮箱：</label>
                        <div class="layui-input-block input-width">
                            <input type="email" name="email" required  lay-verify="required" placeholder="请输入邮箱" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="department" class="layui-form-label label-width">部门：</label>
                        <div class="layui-input-block input-width">
                            <div class="layui-select-title" >
                                <select name="department" lay-filter="filter" >
                                    <option value="56">信息部</option>
                                    <option value="57">燃料管理部</option>
                                    <option value="58">公司领导</option>
                                    <option value="59">宣传部</option>

                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="phone" class="layui-form-label label-width">联系方式：</label>
                        <div class="layui-input-block input-width">
                            <input type="text" name="phone" required  lay-verify="required" placeholder="请输入联系方式" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label for="role" class="layui-form-label label-width">默认角色：</label>
                        <div class="layui-input-block input-width">
                            <input type="text" value="系统管理员" disabled id="role" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input layui-disabled">
                        </div>
                    </div>

                    <br>
                    <div class="layui-form-item">
                        <div class="layui-input-block input-width">
                            <button class="layui-btn layui-btn-radius " lay-submit lay-filter="formDemo">立即提交</button>
                            <button type="reset" class="layui-btn layui-btn-radius layui-btn-primary">重置</button>
                             <button type="button" class="layui-btn layui-btn-radius layui-btn-primary" onclick="window.history.go(-1)">返回</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <#include "/base/main-footer.ftl">
</div>

<script src="/lib/layui/layui.js"></script>
<script>
    layui.use(['layer', 'form', 'element', 'jquery'], function () {
        let layer = layui.layer, form = layui.form, $ = layui.jquery;
        let loading = false
        form.on('submit(formDemo)',function (data) {
            if(loading){
                return false
            }
            loading = true
           $.ajax({
               type: "post",
               url: "/addMember.do",
               contentType: "application/json;charset=utf-8",
               data:JSON.stringify(data.field),
              success: function (message) {
                   if (message.isSuccess){
                       layer.alert("用户添加成功!2秒后跳转到列表");
                       loading = false
                       setTimeout('window.location = "/member"', 2000);
                   } else {
                       loading = false
                       layer.alert(message.msg);
                   }
               }
           });
           return false;
        });
        form.on('select(filter)', function(data){
            var dep=data.value;
            if(dep==56){
                $("#role").val("系统管理员");
            }
            if(dep==57){
                console.log(data.value);
                $("#role").val("燃料业务人员");
            }
            if(dep==58){
                $("#role").val("管理人员");
            }
            if(dep==59){
                $("#role").val("公告通知发布人员");
            }

        });


    });


</script>
</body>
</html>